local gongzhu = fk.CreateSkill {
  name = "lingling__gongzhu",
}

Fk:loadTranslationTable{
  ["lingling__gongzhu"] = "功逐",
  [":lingling__gongzhu"] = "当你使用锦囊牌/基本牌后，你可以令一名手牌少于你/体力多于你的角色摸一张牌。",

  ["#lingling__gongzhu-choose"] = "功逐：你可以令一名角色摸一张牌",
}

gongzhu:addEffect(fk.CardUseFinished, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(gongzhu.name) then
      if data.card.type == Card.TypeTrick then
        return table.find(player.room.alive_players, function (p)
          return p:getHandcardNum() < player:getHandcardNum()
        end)
      elseif data.card.type == Card.TypeBasic then
        return table.find(player.room.alive_players, function (p)
          return p.hp > player.hp
        end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      if data.card.type == Card.TypeTrick then
        return p:getHandcardNum() < player:getHandcardNum()
      elseif data.card.type == Card.TypeBasic then
        return p.hp > player.hp
      end
    end)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = gongzhu.name,
      prompt = "#lingling__gongzhu-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    event:getCostData(self).tos[1]:drawCards(1, gongzhu.name)
  end,
})

return gongzhu
